#ifndef _CONTRA_H
#define _CONTRA_H
#include "Character.h"
#include "Sprite.h"
#include "Collision.h"
#include "GunContra.h"
#include "Sound.h"
#include "CollisionMap.h"

#include <conio.h>
#include <iostream>
using namespace std;

class CContra :
	public CCharacter
{
private:
	CSprite *_rSprite;
	CSprite *_lSprite;
	CSprite *_fSprite;
	CSprite *_bossLight;

	bool _isRight;
	bool _isJump;
	bool _isMove;
	int _isDown;
	DWORD frame_start;
	DWORD tick_per_frame;
	int vpx, vpy;

	// bullet
	CSprite *_sprite_bullet;
	CGunContra _gunContra;
	bool _gun;
	DWORD _gun_start;
	DWORD _tick_per_gun;
	DWORD _bullet_start;
	DWORD _tick_bullet;
	int _levelBullet;
	Sound _sound;
	CSound *_CSound;

	#pragma region DANG
	
	//map de xu ly va cham
	CCollisionMap _collisionMap;

	//ground y
	int _groundY;

	//trang thai boi
	bool _isSwim;

	//trang thai dung tren dat
	bool _isOnLand;

	//trang thai roi
	bool _isFall;

	//tile number cua rectangle ma contra dung truoc do 
	int _lastTileNumber;

	//
	DWORD _dwStartFall;

	//
	DWORD _dwFallTime;

	#pragma endregion

public:
	CContra();
	~CContra(void);
	int ContraLoadSound(Sound isound);
	void LoadResource(LPDIRECT3DDEVICE9 d3ddv, LPD3DXSPRITE &SpriteHandler, HINSTANCE hInstance, HWND hWnd);	
	void ProcessInput();
	void ContraGun();
	void OnKeyDown(int KeyCode);
	void Contra_Run();
	void Update();
	void Render();
	void Contra_End();
	void ReadFileInputData(void);

	#pragma region DANG

	//xu ly va cham tren map
	void HandleCollisionOnMap();

	int FindLandToStand(int indexHeight, int indexWidth);

	//lay box de xet va cham
	Box GetBox();

	void StartFall();

	void ProcessFall();

	void EndFall();

	#pragma endregion
};
#endif
